package com.yincb.sort;


import java.util.Arrays;

/**
 * 冒泡排序
 */
public class BubbleSort {


    public static void main(String[] args) {

        int[] data = {4, 5, 6, 3, 2, 1};
        int n = data.length - 1;

        for (int i = 0; i < n; i++) {          // O(n^2)
            for (int j = 0; j < n - i; j++) {
                int tem = data[j];
                if (data[j] > data[j+1]) {
                    data[j] = data[j+1];
                    data[j+1] = tem;
                }
            }
            System.out.println(Arrays.toString(data));
        }


    }


}
